
/*

Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
using System;using BusinessLayer;using InfoClasses;using dpatoolkit.UILayer;
using System.Data;
using DesignPatternDefinitions;
using System.Collections;

namespace BusinessLayer
{
	/// <summary>
	/// Represents a field that implements IField
	/// </summary>
	public class DPField : IField
		
	{
		private string compName, cName, fldName;
		private DataTable fieldTable;
		private DataRow fieldRow;

		public DPField(string comp,string cls,string fld,DataTable fldTb)
		{
			this.compName=comp;
			this.cName=cls;
			this.fldName=fld;
			this.fieldTable = fldTb;
			this.fieldRow = this.fieldTable.Rows.Find(new object[]
				{
					this.compName,this.cName,this.fldName
				}
				);
			if(this.fieldRow==null)
			{
				ErrorMessage.Show("Internal Error: Invalid field encountered in DPField","Internal error");
			}
		}
		public DPField(string comp,string cls,string fld,DataRow fldRw)
		{
			this.compName=comp;
			this.cName=cls;
			this.fldName=fld;
			this.fieldRow = fldRw;
			
		}

		#region IField Members
		public string GetMetaInfo(string language)
		{
			MetaInfoEditor mie = new MetaInfoEditor((string)this.fieldRow[SchemaNames.MetaInfo]);
			return mie.GetMetaInfo(language);
		}
		public void SetMetaInfo(string minfo)
		{
			//Not Required....protection against plugins.
		}

		public string FieldName
		{
			get
			{
				return this.fldName;
			}
			set
			{
				this.fldName=value as string;
			}
		}

		public string UMLRepresentation
		{
			get
			{
				string vis = (string)this.fieldRow[SchemaNames.Visibility];
				if(vis=="private") vis="-";
				else if(vis=="public") vis="+";
				else vis="#";

				return vis+
					this.fldName + ":" +(string) this.fieldRow[SchemaNames.FieldType] ;
			}
		}
		public object FieldUID
		{
			get{ return this.fieldRow[SchemaNames.FieldName]; }
		}

		public string FieldType 
		{
			get 
			{
				return (string)this.fieldRow[SchemaNames.FieldType];
			}
			set 
			{
				this.FieldType=value as string;
			}
		}

		public string FieldVisibility 
		{
			get 
			{
				return (string) this.fieldRow[SchemaNames.Visibility];
			}
			set 
			{
				this.FieldVisibility=value as string;
			}
		}

		public string FieldSummary 
		{
			get 
			{
				return (string)this.fieldRow[SchemaNames.Summary];
			}
			set 
			{
				this.fieldRow[SchemaNames.Summary]=(string)value;
			}
		}
		public Hashtable GetAllMetaInfo()
		{
			MetaInfoEditor mieditor = new MetaInfoEditor((string) this.fieldRow[SchemaNames.MetaInfo] );
			return mieditor.GetAllMetaInfo();
		}

		#endregion
	}
}
